define(['jquery', 'bootstrap', 'backend', 'table', 'form','vue'], function ($, undefined, Backend, Table, Form,Vue) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'express/order/index' + location.search,
                    add_url: 'express/order/add',
                    edit_url: 'express/order/edit',
                    del_url: 'express/order/del',
                    multi_url: 'express/order/multi',
                    import_url: 'express/order/import',
                    table: 'express_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no')},
                        {field: 'user.nickname', title: '下单用户',operate:'LIKE',formatter:function (value,row,index) {
                                return row.user ? "<a href=\"javascript:void(0)\" data-tips-image='"+Fast.api.cdnurl(row.user.avatar)+"'><img class=\"img-sm img-center\" src='"+Fast.api.cdnurl(row.user.avatar)+"'></a>&nbsp;" + value : '';
                            }},
                        {field: 'address.name', title: __('收货人'),operate:'LIKE',  formatter: function (value,row,index) {
                                var html = "<p><span class='text-info'>" + value + "</span>" +
                                    "<span class='text-info' style='margin-left: 10px'>" + row.address.city + "</span></p>";
                                if(row.address.idcard){
                                    html += "<p><button class='btn btn-xs btn-success' data-toggle='popover' data-html='true' data-placement='right' data-content='身份证号:" + row.address.idcard + "'><i class='fa fa-id-card fa-fw'></i> 身份证号 <i class='fa fa-check'></i></button> </p>";
                                }else{
                                    html += "<p><button class='btn btn-xs btn-danger'><i class='fa fa-id-card fa-fw'></i> 身份证号 <i class='fa fa-close'></i></button></p>";
                                }

                                if(row.address.idcard_front && row.address.idcard_reverse){
                                    html += "<p><button class='btn btn-xs btn-success'><i class='fa fa-image fa-fw'></i> 身份证图片 <i class='fa fa-check'></i></button> </p>";
                                }else if(row.address.idcard_front || row.address.idcard_reverse){
                                    html += "<p><button class='btn btn-xs btn-warning'><i class='fa fa-image fa-fw'></i> 身份证图片不完整 <i class='fa fa-close'></i></button> </p>";
                                }else{
                                    html += "<p><button class='btn btn-xs btn-danger'><i class='fa fa-image fa-fw'></i> 身份证图片 <i class='fa fa-close'></i></button> </p>";
                                }

                                return html;
                            }},
                        {field: 'status', title: __('Status'), searchList: {"created":__('Status created'),"package":__('Status package')}, formatter: Table.api.formatter.status},
                        {field: 'delivery_price', title: __('Delivery_price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'),buttons: [
                                {
                                    name: 'edit',
                                    text: __('分箱'),
                                    title: __('分箱'),
                                    classname: 'btn btn-xs btn-editone btn-primary btn-dialog',
                                    icon: 'fa fa-cubes',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == 'created'){
                                            return true;
                                        }else{
                                            return false;
                                        }

                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __('查看包裹'),
                                    title: __('查看包裹'),
                                    classname: 'btn btn-xs btn-primary btn-detail btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'express/package/detail/multi/order',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == 'package'){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },

                            ], table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            table.on('load-success.bs.table',function(data){
                $(".btn-editone").data("area", ["90%","80%"]);
                $(".btn-add").data("area", ["90%","80%"]);
                $(".btn-edit").data("area", ["90%","80%"]);
                $(".btn-detail").data("area", ["90%","80%"]);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            var vm = new Vue({
                el: '#app',
                data() {
                    return {
                        goods:Config.goods,
                        address:Config.address,
                        ruleList:Config.ruleList,
                        packageList:[],
                        categorydata:Config.categorydata,
                        comList:Config.comList
                    }
                },
                methods: {
                    goPackage:function () {
                        var that = this;
                        var loadding = Layer.load();
                        Fast.api.ajax({
                            'url':'express/order/goPackage',
                            'data':{
                                'goods':that.goods
                            }
                        },function (ret) {
                            that.packageList = ret;
                            console.log(that.packageList)
                            Layer.close(loadding);
                        })
                    }
                }
            })
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});